// pages/oneself/collect/collect.js
const app = getApp()
const connector = require('../../../utils/connector.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight + 45,
    shopping: [],//商品

   
  },

  /*跳转商品详情*/
  shoppings: function (e) {
    let shoptwo, shopse;
    app.globalData.shoppingId = e.currentTarget.dataset.id
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '/pages/index/particulars/particulars',
    })
  },
  /**跳转购物车 */
  shopCart: function (e) {
    let addCarts = this.data.addCarts;
    wx.setStorageSync('addCarts', addCarts)
    wx.navigateTo({
      url: '/pages/index/shopCart/shopCart',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    userList(this,1)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
    var that = this
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

//获取我的收藏
function userList(that,page) {
  const pages = {
    page: page
  }
  let font = '正在加载'
  let shopping = that.data.shopping
  connector.getFunc(connector.connector().userList, pages, "get", app.tokens, function (res) {
    console.log(res)

    console.log(res.data.list)
    console.log(res.data.list.data)
    console.log(res.data.list.data[0].goods)
    if (res.statusCode == 200) {
      // console.log(res.data.data)
      if (page == 1) {
        shopping = res.data.list.data[0].goods
        if (res.data.list.data.length < 1) {
          font = "暂无收藏商品"
        } else {
          if (res.data.list.last_page == res.data.list.current_page) {
            font = "没有更多了"
          } else {
            font = "加载完成"
          }
        }
      } else {
        console.log("page>1")
        if (res.data.list.current_page <= res.data.list.last_page) {
          shopping = shopping.concat(res.data.list.data[0].goods)
          if (res.data.list.current_page == res.data.list.last_page) {
            font = "没有更多了"
          } else {
            font = "加载完成"
          }
        }
      }
      console.log(shopping)
      that.setData({
        shopping: shopping,
        font: font,
      })

    } else {
      wx.showToast({
        title: res.statusCode + ":" + res.errMsg,
        icon: 'none',
        duration: 1000
      })
    }
  }, function (res) {
    wx.showToast({
      title: "内部错误",
      icon: 'none',
      duration: 1000
    })
  })
}